
<template>
  <div class="login-container">

    <!-- 顶部背景图区域 -->
    <div class="login-header">
      <van-icon name="arrow-left" size="20" class="arrow" @click="router.back()"/>
      <h1>注册账号</h1>
      <div></div>
    </div>

    <!-- 登录表单区域 -->
    <div class="login-form">
      <van-form @submit="handleRegister">
        <van-cell-group inset>
          <p class="phone">手机号</p>
          <van-field
            class="phone-field"
            v-model="registerForm.phone"
            name="手机号"
            placeholder="请输入手机号"
            :rules="[{ required: true, message: '请填写手机号' }]"
          />
          <p class="password">密码</p>
          <van-field
            class="password-field"
            v-model="registerForm.password"
            type="password"
            name="密码"
            placeholder="请输入密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <p class="phone">用户名</p>
          <van-field
            class="phone-field"
            v-model="registerForm.username"
            name="用户名"
            placeholder="请输入用户名"
            :rules="[{ required: true, message: '请填写昵称' }]"
          />
        </van-cell-group>
        <div class="agree">
           <van-radio type="square" class="agree-btn">
        </van-radio>
         <div class="login-info"> 我已阅读并同意《用户协议》和《隐私政策》</div>
        </div>

        <div class="login-actions">
          <van-button class="login-btn" round block  native-type="submit">
            注册
          </van-button>
          <div class="quick-actions">
            <span @click="router.push({name:'login'})">已有账号，去登录</span>
          </div>
        </div>
      </van-form>


    </div>
  </div>
</template>

<script setup name="Login">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { showFailToast, showSuccessToast, showToast } from 'vant';
import { useUserInfoStore } from '../stores/userInfo';
import { register } from '../api';


const router = useRouter();
const userInfoStore = useUserInfoStore()
const registerForm = ref({
  phone:"",
  password:"",
  username:""
})


const handleRegister = async ()=>{
  try{
    await register(registerForm.value)
    showSuccessToast("注册成功")
    router.push({name:'login'})
  }catch(e){
    console.log(e);
    showFailToast("注册失败")
  }
}


</script>

<style lang='less' scoped>
.login-container {
  height: 100%;
  background-color: #f7f7f7;
}

.login-header {
  position: relative;
  height: 32vh;
  background-color: #FED933;
  background-image: url(../img/dog.png);
  background-repeat: no-repeat;
  background-size: 50%;
  background-position: right bottom;

  div{
    position: absolute;
    bottom: -1px;
    width: 100%;
    height: 20px;
    border-radius: 20px 20px 0 0;
    background-color: white;
  }
  .arrow{
    position: absolute;
    left: 10px;
    top: 20px;
  }
}



.login-header h1 {
  position: absolute;
  bottom: 30px;
  left: 20px;
  right: 0;
  text-align: left;
  font-size: 24px;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

.login-form {
  padding: 20px;
  margin-top: -15px;
  background: white;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -5px 10px rgba(0,0,0,0.05);
}

.login-info{
  margin-top: 0px;
  font-size: 14px;

}

.login-actions {
  margin: 20px 0;
  margin-top: 20px;
}

.quick-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 15px;
  font-size: 14px;
  color: #1989fa;
}

.social-login {
  margin-top: 40px;
  text-align: center;
}

.social-login p {
  color: #969799;
  font-size: 14px;
  margin-bottom: 15px;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 30px;
}


::v-deep .van-field__control::placeholder {
  color: #c0c4cc; /* 提示语颜色（浅灰色，更柔和） */
  font-size: 16px; /* 提示语字体大小（比输入文字稍小） */
  opacity: 0.8; /* 透明度（可选） */
  padding-left: -30px;

}
.phone{
  font-weight: bold;
  color: #4b4c4e;
  font-size: 20px;
}
.agree{
  display: flex;
  margin-top: 40px;
}
.agree-btn{
  margin-left: 5px;
  margin-right: 8px;
}

.password{
  font-size: 20px;
  font-weight: bold;
  color: #4b4c4e;
}

.phone-field{
  margin-left: -10px;

  border-bottom: 2px solid #4b4c4e;
}
.password-field{
  margin-left: -10px;
  border-bottom: 2px solid #4b4c4e;
}

.login-btn{
 background-color: #FFD700;
  color: #333;
  border-radius: 30px;
  padding: 14px 32px;
  min-width: 120px;
  font-weight: bold;
  font-size: 18px;
}
</style>
